#ifndef PROJECT_STARTUP_INTERFACE_H
#define PROJECT_STARTUP_INTERFACE_H

#include <QDialog>
#include <QFile>
#include <QTreeWidgetItem>
#include <QtXml>
#include <QMap>
#include <QList>
#include <QVector>

#define ProStoreFolder QMap<int, QString>
#define FolderPath QList<QString>

#define ProStoreFolderPath QMap<ProStoreFolder *, FolderPath> // QVector< QMap<int, QString>, QList<QString> >

#ifndef PROSTARTUP_NEWPRO_H
#include "project_startup/prostartup_newpro.h"
#endif

namespace Ui {
class project_startup_interface;
}


struct ProStartupInt_Config  // 工程仓库配置结构体
{
    QString proStoreFilePath;  // 工程仓库文件存放路径
    QString proStoreFileName;  // 工程仓库文件名
    QString defaultProNewFilePath;    // 默认工程存放位置

    QString get_proStoreFile()
    {
        return QString(proStoreFilePath + proStoreFileName);
    }
};

struct Map_Dictionary
{
    bool ret;
    Project_Path path;
};


class project_startup_interface : public QDialog
{
    Q_OBJECT

public:
    explicit project_startup_interface(QWidget *parent = nullptr);
    ~project_startup_interface();

    void delete_node(QTreeWidgetItem *item, bool judgeDeleteFile = false);

    void add_node(Project_Path);

    static ProStoreFolderPath get_proStoreFolderPath(QTreeWidgetItem *root);
    static FolderPath get_folderPath(QTreeWidgetItem *folder);

public slots:
    void recv_newPro(Project_Path);

private slots:
    void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);

    void on_pushButton_add_project_clicked();

    void on_pushButton_deletePro_clicked();

    void on_pushButton_importPro_clicked();

private:
    Ui::project_startup_interface *ui;

    ProStartupInt_Config proStoreConfig;
    QMap<QTreeWidgetItem *, Project_Path> projectMap;

    bool delFileCheck;

    void load_proStoreConfig();   // 加载工程配置
    void check_proStoreConfig();  // 检测工程库配置

    void load_proTree();   // 加载工程仓库树
    void init_proStoreFile(QFile *file);  // 初始化工程仓库文件
    void make_proTree(QDomNodeList list, QTreeWidgetItem *item = nullptr);

    int init_proFile(QString file_path);  // 创建与初始化工程文件

    void interface_exit(Project_Path proPath);

    Map_Dictionary map_indexOfproPath(QTreeWidgetItem *item);

signals:
    void sendData(Project_Path);
};


#endif // PROJECT_STARTUP_INTERFACE_H
